package com.skstudio.reportview;

import java.util.ArrayList;
import com.skstudio.report.ReportCpuSpeed;
import com.skstudio.report.ReportCpuSpeed.DataSpeed;
import com.skstudio.report.SpyData;

public class ReporterCoreSpeed extends ReportViewController {

    ReportCpuSpeed mCpu = null;

    @Override
    public void setSpyData(SpyData ref) {
        super.setSpyData(ref);
        mCpu = ref.getReportCpuSpeed();
    }

    @Override
    public int getReportRows() {
        return mCpu.mDataList.size();
    }

    @Override
    public int getReportColumns() {
        if (mCpu.mDataList.size() > 0) {
            return mCpu.mDataList.get(0).size();
        }
        return 0;
    }

    @Override
    public int getEntry(int row, int col) {
        if (mCpu.mDataList.size() > row) {
            ArrayList<DataSpeed> list = mCpu.mDataList.get(row);
            if (list.size() > col) {
                return (int) (list.get(col).mCur * 100 / list.get(col).mMax);
            }
            return 0;
        }
        return 0;
    }

    @Override
    public String getReportDescription() {
        return "CPU Frequence Per Core";
    }

    @Override
    public String getEntryName(int row) {
        if (mCpu.mDataList.size() > row) {
            ArrayList<DataSpeed> list = mCpu.mDataList.get(row);
            if (list.size() > 0) {
                return String.format("Core #%d frequence (min %dMhz, max %dMhz)", row, list.get(0).mMin, list.get(0).mMax);
            }
        }
        return null;
    }

    @Override
    public String getEntryHint(int col) {
        StringBuilder sb = new StringBuilder();
        sb.append("Current ");
        for (int ii = 0; ii < mCpu.mDataList.size(); ii++) {
            if (ii == 0) {
                sb.append(String.format("%dMhz", mCpu.mDataList.get(ii).get(col).mCur));
            } else {
                sb.append(String.format(", %dMhz", mCpu.mDataList.get(ii).get(col).mCur));
            }
        }
        return sb.toString();
    }
}
